home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d1 / freemacs.arc / DEV11.ASM < prev    next >
Assembly Source File  |  1988-03-17  |  7KB  |  248 lines

  1.         name    DEV
  2.         page    60,132
  3.         title   'DEV --- Report installed device drivers'
  4.  
  5. ; DEV --- a utility to report device header information for
  6. ;         all installed device drivers
  7. ; Requires PC-DOS or MS-DOS 2.0.
  8. ;
  9. ; Used in the form:
  10. ; A>DEV 
  11. ;
  12. ; version 1.0   December 12, 1984
  13. ; Copyright (c) 1984 by Ray Duncan
  14. ;
  15. ; version 1.1   October 19, 1986
  16. ; modified by Brian J. Larson
  17. ;
  18. ; In DOS 3.2 the reserved area of the FCB has been changed.  The
  19. ; segment still seems right but the offset does not point to NUL
  20. ; so 48h is forced into the offset. Reserved must mean RESERVED!
  21. ;
  22. cr      equ     0dh             ;ASCII carriage return
  23. lf      equ     0ah             ;ASCII line feed
  24. blank    equ    20h        ;ASCII space code
  25. eom    equ    '$'        ;end of string marker
  26.  
  27.  
  28. cseg    segment    para public 'CODE'
  29.  
  30.     assume    cs:cseg,ds:data,es:data,ss:stack
  31.  
  32.  
  33. dev     proc    far             ;entry point from PC-DOS
  34.  
  35.         push    ds              ;save DS:0000 for final
  36.         xor     ax,ax           ;return to PC-DOS
  37.         push    ax
  38.         mov     ax,data         ;make our data segment
  39.     mov    ds,ax        ;addressable via DS and ES.
  40.     mov     es,ax 
  41.         mov     ah,30h        ;check version of PC-DOS.    
  42.         int     21h
  43.         cmp     al,2
  44.         jae     dev1        ;proceed, DOS 2.0 or greater.
  45.         mov     dx,offset msg2  ;DOS 1.x --- print error message.
  46.     jmp    dev6
  47.  
  48. dev1:    mov    cx,ax        ;save DOS version number.
  49.     mov    ah,15        ;now try and open the "NUL" device.
  50.     mov    dx,offset nulfcb
  51.     int    21h
  52.     or    al,al        ;opened successfully?
  53.     jz    dev2        ;yes, jump.
  54.     mov    dx,offset msg1    ;no, print error msg and exit.
  55.     jmp    dev6
  56.  
  57. dev2:                ;Pick up double pointer to device 
  58.                 ;driver chain out of reserved
  59.                 ;area in fcb.  This area is mapped
  60.                 ;differently in DOS 2.x and DOS 3.x.
  61.     cmp    cl,2        ;is this DOS 2.x?
  62.     ja    dev3        ;no, jump.
  63.     mov    bx,word ptr nulfcb+25
  64.     mov    es,word ptr nulfcb+27
  65.     jmp    dev4
  66.  
  67. dev3:                ;come here if DOS 3.0 or greater.
  68.     cmp    ch,2        ;compare minor - DOS 3.2 or greater?
  69.     jae    dev32        ;yes, jump.
  70.     mov    bx,word ptr nulfcb+26
  71.     mov    es,word ptr nulfcb+28
  72.     jmp    dev4
  73.  
  74. dev32:                ;come here if DOS 3.2 or above
  75.     mov    bx,48h        ;value at nulfcb+26 is C2h but NUL is at 48h
  76.     mov    es,word ptr nulfcb+28
  77.  
  78. dev4:    call    header        ;print sign-on message and 
  79.                 ;column headings.
  80.  
  81. dev5:                ;trace through the device chain
  82.  
  83.     call    prdev        ;print device header information
  84.                 ;for driver pointed to by ES:BX.
  85.                 ;pick up addr of next header.
  86.     les    bx,dword ptr es:[bx]
  87.     cmp    bx,-1        ;found last one yet?
  88.     jne    dev5        ;no, try next.
  89.     
  90.           mov    dx,offset msg3    ;yes, print "end of device chain".
  91.  
  92. dev6:     mov    ah,9        ;print the string whose address
  93.     int    21h        ;is in DX.
  94.     ret            ;then return to DOS.
  95.  
  96. dev       endp
  97.  
  98.  
  99. header    proc    near        ;print out headings for device
  100.     mov    dx,offset hdr    ;driver information.
  101.     mov    ah,9
  102.     int    21h
  103.     ret
  104. header    endp
  105.  
  106.  
  107. prdev    proc    near        ;print out device driver info.
  108.                 ;ES:BX is pointer to device header,
  109.                 ;which must be preserved.
  110.     mov    ax,es        ;convert segment of device header
  111.     mov    di,offset inf1
  112.     call    hexasc
  113.     mov    ax,bx        ;convert offset of device header.
  114.     mov    di,offset inf2
  115.     call    hexasc
  116.     mov    ax,es:[bx+4]    ;get attribute word, save a 
  117.     push    ax        ;copy of it, then convert it.
  118.     mov    di,offset inf3
  119.     call    hexasc
  120.     mov    ax,es:[bx+6]    ;convert ptr to device strategy.
  121.     mov    di,offset inf4
  122.     call    hexasc
  123.     mov    ax,es:[bx+8]    ;convert ptr to device int handler.
  124.     mov    di,offset inf5
  125.     call    hexasc
  126.  
  127.                 ;if not char device, clear out name
  128.                 ;field and set number of units.
  129.     pop    ax        ;get back attribute word.
  130.     test    ax,08000h    ;is bit 15 = 1 ?
  131.     jnz    prdev7        ;yes, it's character dev, jump.
  132.                           ;no, it's block device.
  133.                 ;set flag to skip device name.
  134.     mov     byte ptr inf8,eom
  135.     mov    al,es:[bx+10]    ;pick up number of units.
  136.     aam            ;convert to ASCII decimal and
  137.     add    ax,'00'        ;store into output string.
  138.     mov    byte ptr inf7+1,al
  139.     mov    byte ptr inf7,ah
  140.                 ;set type = B for Block
  141.     mov    byte ptr inf6,'B'    
  142.     jmp    prdev9
  143.  
  144. prdev7:                ;if char device, move its 8-character
  145.                 ;name into the output string.
  146.     xor    si,si
  147. prdev8:    mov    al,es:[si+bx+10]
  148.     mov    [si+inf8],al
  149.     inc    si
  150.     cmp    si,8
  151.     jne    prdev8
  152.                 ;remove # of units field.
  153.     mov    word ptr inf7,'  '
  154.                 ;set type = C for Character.
  155.     mov    byte ptr inf6,'C'
  156.  
  157. prdev9: mov    dx,offset inf    ;now print device information
  158.     mov    ah,9        ;and exit.
  159.     int    21h
  160.     ret
  161. prdev    endp
  162.  
  163. hexasc    proc    near        ;convert binary word to hex ASCII.
  164.                 ;call with AX=binary value
  165.                 ;          DI=addr to store string 
  166.                 ;returns AX, CX, DI destroyed.
  167.     push    ax        ;save copy of original value.
  168.     mov    al,ah
  169.     call    btoa        ;convert upper byte.
  170.     add    di,2        ;increment output address.
  171.     pop    ax
  172.     call    btoa        ;convert lower byte.
  173.     ret            ;return to caller.
  174. hexasc    endp
  175.  
  176. btoa    proc    near        ;convert binary byte to hex ASCII.
  177.                 ;call with AL=binary value 
  178.                 ;          DI=addr to store string
  179.                 ;returns AX, CX destroyed.
  180.     mov    ah,al        ;save lower nibble.
  181.     mov    cx,4        ;shift right 4 positions
  182.     shr    al,cl        ;to get upper nibble.
  183.     call    ascii        ;convert 4 bits to ASCII equivalent
  184.     mov    [di],al        ;store into output string.
  185.     mov    al,ah        ;get back lower nibble.
  186.     and    al,0fh
  187.     call    ascii        ;convert 4 bits to ASCII
  188.     mov     [di+1],al    ;and store into output string.
  189.     ret            ;back to caller.
  190. btoa    endp
  191.  
  192. ascii    proc    near        ;convert 4 lower bits of AL
  193.     add    al,'0'        ;into the equivalent ASCII char.
  194.     cmp    al,'9'        ;in the range {0...9,A...F}
  195.     jle    ascii2        ;and return char. in AL.
  196.     add    al,'A'-'9'-1    ;"fudge factor" for range A-F.
  197. ascii2:    ret            ;return to caller.
  198. ascii    endp
  199.  
  200. cseg    ends
  201.  
  202.  
  203. data    segment para public 'DATA'
  204.  
  205. msg1    db    cr,lf
  206.     db    'Failed to open NUL device.'
  207.     db    cr,lf,eom
  208.  
  209. msg2    db      cr,lf
  210.         db      'Requires DOS version 2 or greater.'
  211.         db      cr,lf,eom
  212.  
  213. msg3    db    cr,lf
  214.     db    'End of device chain.'
  215.     db    cr,lf,eom
  216.  
  217. hdr    db    cr,lf
  218.     db    'Addr      Attr '
  219.     db    'Str  Int   Type  Units  Name   '
  220.     db    eom
  221.  
  222.  
  223. inf     db    cr,lf
  224. inf1    db    'XXXX:'        ;seg device header
  225. inf2    db    'XXXX '        ;offs device header
  226. inf3    db    'XXXX '        ;attribute
  227. inf4    db    'XXXX '        ;strategy
  228. inf5    db    'XXXX   '    ;interrupt handler
  229. inf6    db    'X     '    ;type (block or char)
  230. inf7    db    'XX    '    ;units (if block device)
  231. inf8    db    '         '    ;name  (if char device)
  232.     db    eom
  233.  
  234.                 ;fcb to open NUL device
  235. nulfcb    db    0        ;drive
  236.     db    'NUL'        ;name of NUL device
  237.     db    8 dup (' ')
  238.     db    25 dup (0)
  239. data    ends    
  240.  
  241.  
  242. stack   segment para stack 'STACK'
  243.         db      64 dup (?)
  244. stack   ends
  245.  
  246.         end     dev
  247.